const Mock = require('mockjs')
const express = require('express')
const bodyParser = require('body-parser')
const mockRouter = express.Router() // express路由
const Random = Mock.Random // mock的方法

mockRouter.use(bodyParser.json())
mockRouter.use(bodyParser.urlencoded({ extended: true }))

const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
}

// method: post
// path: /data
mockRouter.post(new RegExp('/user/login'), (req, res) => {
  const data = {
    code: 20000,
    token: tokens[req.body.username].token,
    email: Random.email()
  }
  res.json(data)
})
module.exports = mockRouter
